package cn.edu.neu.controller.manage;

import cn.edu.neu.model.TravelNotesType;
import cn.edu.neu.service.TravelNotesTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import java.util.List;

@RequestMapping("/travelType")
@Controller
public class TravelNotesTypeController {

    @Autowired
    private TravelNotesTypeService travelNotesTypeService;

    @RequestMapping("/getTravelNotesTypeList")
    public String getScenicSpotList(Model model){
        List<TravelNotesType> travelNotesTypeList =travelNotesTypeService.getTravelNotesTypeList();
        model.addAttribute("travelNotesTypeList",travelNotesTypeList);
        return "/manage/travel-type/travelNotesType";
    }
    @RequestMapping("toAddPage")
    public String toAddPage(){
        return "/manage/travel-type/addTravelNotesType";
    }
    @RequestMapping("/submitTravelNotesType")
    public String addScenicSpotsType(TravelNotesType travelNotesType){

        travelNotesTypeService.insertTravelNotesType(travelNotesType);
        return "redirect:/travelType/getTravelNotesTypeList";
    }

    @RequestMapping("/updateTravelNotesType/{id}")
    public String toUpdate(@PathVariable("id") Integer id, Model model){
        TravelNotesType travelNotesType = travelNotesTypeService.getTravelNotesTypeById(id) ;
        model.addAttribute("travelNotesType",travelNotesType) ;
        return "/manage/travel-type/updateTravelNotesType";
    }
    @RequestMapping("/submitUpdateTravelNotesType")
    public String updateTravelNotesType(TravelNotesType travelNotesType){
        travelNotesTypeService.updateTravelNotesType(travelNotesType) ;
        return  "redirect:/travelType/getTravelNotesTypeList";
    }
    @RequestMapping("/deleteTravelNotesType/{id}")
    public String deleteBuy(@PathVariable("id") Integer id){
        int i=travelNotesTypeService.deleteTravelNotesType(id);
        return "redirect:/travelType/getTravelNotesTypeList";

    }
}
